package com.ruoyi.controller.fanruan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.jpjs.common.fanruan.TzFirst;
import com.ruoyi.service.fanruan.ITzFirstService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 投资集团Controller
 *
 * @author ruoyi
 * @date 2020-11-04
 */
@Controller
@RequestMapping("/fanruan/tz")
public class TzFirstController extends BaseController
{
    private String prefix = "fanruan/tz";

    @Autowired
    private ITzFirstService tzFirstService;

    @RequiresPermissions("fanruan:tz:view")
    @GetMapping()
    public String tz()
    {
        return "fanruan/tz/tz";
    }

    /**
     * 查询投资集团列表
     */
    @RequiresPermissions("fanruan:tz:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TzFirst tzFirst)
    {
        startPage();
        List<TzFirst> list = tzFirstService.selectTzFirstList(tzFirst);
        return getDataTable(list);
    }

    /**
     * 导出投资集团列表
     */
    @RequiresPermissions("fanruan:tz:export")
    @Log(title = "投资集团", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TzFirst tzFirst)
    {
        List<TzFirst> list = tzFirstService.selectTzFirstList(tzFirst);
        ExcelUtil<TzFirst> util = new ExcelUtil<TzFirst>(TzFirst.class);
        return util.exportExcel(list, "tz");
    }

    /**
     * 新增投资集团
     */
    @GetMapping("/add")
    public String add()
    {
        return "fanruan/tz/add";
    }

    /**
     * 新增保存投资集团
     */
    @RequiresPermissions("fanruan:tz:add")
    @Log(title = "投资集团", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TzFirst tzFirst)
    {
        return toAjax(tzFirstService.insertTzFirst(tzFirst));
    }

    /**
     * 修改投资集团
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TzFirst tzFirst = tzFirstService.selectTzFirstById(id);
        mmap.put("tzFirst", tzFirst);
        return "fanruan/tz/edit";
    }

    /**
     * 修改保存投资集团
     */
    @RequiresPermissions("fanruan:tz:edit")
    @Log(title = "投资集团", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TzFirst tzFirst)
    {
        return toAjax(tzFirstService.updateTzFirst(tzFirst));
    }

    /**
     * 删除投资集团
     */
    @RequiresPermissions("fanruan:tz:remove")
    @Log(title = "投资集团", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tzFirstService.deleteTzFirstByIds(ids));
    }
}
